<template>
    <view>
        <view class="pages" style="box-shadow: 2px 4px 8px 0px #f5f5f5" @tap.stop.prevent="gotoSelectAddress">
            <view class="topbox" v-if="listStatus">
                <view class="flexs align-center">
                    <image src="/static/images/adds.png" class="topboxaddicon margin-right"></image>
                    <view>
                        <view class="toptext">
                            <view class="text-black text-lg text-bold">{{ defaultAddress.name }}</view>
                            <view class="text-black text-df padding-left-xs">{{ defaultAddress.phone }}</view>
                        </view>
                        <view class="text-df text-darkGray padding-top-xs" style="width: 530rpx">
                            {{ defaultAddress.province }}{{ defaultAddress.city }}{{ defaultAddress.region }}{{ defaultAddress.detailAddress || '请添加收货地址' }}
                        </view>
                        <view class="text-red text-sm padding-tb-xs" v-if="feight.remark != null && goodsInfo.freightAomunt > 0">{{ feight.remark }}</view>
                    </view>
                </view>
                <image src="/static/images/righticon.png" class="toprighticon margin-right-xs"></image>
            </view>
        </view>
        <view class="pages" v-if="tap">
            <view class="shoptexts">
                <view class="shoptext">
                    <image :src="goodsInfo.mallSkuStockDto.pic" class="shopimg"></image>
                    <view class="margin-right" style="width: 470rpx">
                        <view class="text-black text-df text-bold text-tline">{{ goodsInfo.mallSkuStockDto.productName }}</view>
                        <view class="text-darkGrey text-sm margin-top-sm">{{ spType }} | 数量:x{{ goodsInfo.mallSkuStockDto.quantity }}</view>
                        <view v-if="checkMaker && goodsInfo.mallSkuStockDto.priceMaker" class="text-lg text-red">
                            <text>¥{{ goodsInfo.mallSkuStockDto.priceMaker }}</text>
                            <text class="text-through text-darkGray padding-left-sm text-sm">¥{{ goodsInfo.mallSkuStockDto.price }}</text>
                        </view>
                        <view v-else class="text-lg text-price text-red" style="padding-top: 10rpx">{{ goodsInfo.mallSkuStockDto.price }}</view>
                    </view>
                </view>
                <view class="storetext" v-if="storeid != undefined && storeid">
                    <view class="flexs align-center">
                        <image src="https://yiyueuser.oss-cn-shenzhen.aliyuncs.com/2022-02-15/92b0b6c61ee6472c9f0d4961963c57a5-file" class="storeimg"></image>
                        <view style="width: 500rpx">
                            <view>{{ storename }} {{ mobile }}</view>
                            <view>{{ path }}</view>
                        </view>
                    </view>
                    <view class="flexs align-center">
                        <view :data-id="item.productId" :data-item="item" @tap="handDistributions">切换</view>
                        <image class="icon-32" src="https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/right.png"></image>
                    </view>
                </view>
                <view class="storebtn" v-if="goodsInfo.mallProductDto.distributionType == 3" :data-id="item.productId" :data-item="item" @tap="handDistribution">
                    {{ storeid ? '切换快递' : '切换自提' }}
                </view>
                <view :class="storeid ? 'storebtns' : 'storebtn'" v-if="goodsInfo.mallProductDto.distributionType == 2" @tap="handDistribution">
                    {{ storeid ? '已选' : '选门店' }}
                </view>
            </view>
            <view class="storealign margin-bottom-sm" v-if="goodsInfo.mallProductDto.distributionType == 3">亲~可选择上门自提，下单后可出示核销码到门店提取</view>
            <view class="storealign margin-bottom-sm" v-if="goodsInfo.mallProductDto.distributionType == 2">亲，此商品仅能上门自提，下单后可出示核销码到门店提货</view>
        </view>
        <view class="pages" v-else>
            <view class="shoptext2" v-for="(item, index) in goodsInfo.mallCartItemDtos" :key="index">
                <view class="flexs margin-top-sm">
                    <image :src="item.pic" class="shopimg"></image>
                    <view class="margin-right" style="width: 470rpx">
                        <view class="text-black text-df text-bold text-tline">{{ item.productName }}</view>
                        <view class="text-darkGrey text-sm margin-top-sm">{{ item.spType }} | 数量:x{{ item.quantity }}</view>
                        <view v-if="checkMaker && item.priceMaker" class="text-lg text-price text-red">
                            <text>¥{{ item.priceMaker }}</text>
                            <text class="text-through text-darkGray padding-left-sm text-sm">¥{{ item.price }}</text>
                        </view>
                        <view v-else class="text-lg text-price text-red" style="padding-top: 10rpx">{{ item.price }}</view>
                    </view>
                </view>

                <view class="stroes">
                    <view class="storetext" v-if="item.storeId != undefined && item.storeId && item.distributionType == 2">
                        <view class="flexs align-center">
                            <image src="https://yiyueuser.oss-cn-shenzhen.aliyuncs.com/2022-02-15/92b0b6c61ee6472c9f0d4961963c57a5-file" class="storeimg"></image>
                            <view style="width: 500rpx">
                                <view>{{ item.storename }} {{ item.mobile }}</view>
                                <view>{{ item.storeAddress }}</view>
                            </view>
                        </view>
                        <view class="flexs align-center" :data-id="item.productId" :data-item="item" @tap="handDistributions">
                            <view>切换</view>
                            <image class="icon-32" src="https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/right.png"></image>
                        </view>
                    </view>
                    <view v-if="item.productDistributionType == 3">
                        <view
                            :class="item.storeId && item.distributionType == 2 ? 'storebtns' : 'storebtn'"
                            :data-index="index"
                            v-if="item.productDistributionType == 3 && item.distributionType != 2 && item.distributionType != 1"
                        >
                            请选自提门店
                        </view>
                        <view
                            class="storebtn"
                            :data-index="index"
                            v-if="item.distributionType == 2"
                            :data-id="item.productId"
                            :data-item="item"
                            @tap="handDistribution"
                            :data-type="item.storeId && item.distributionType == 2 ? 2 : ''"
                        >
                            {{ item.storeId && item.distributionType == 2 ? '切换快递' : '选门店' }}
                        </view>
                        <view class="storebtn" :data-id="item.productId" :data-item="item" v-if="item.distributionType == 1" @tap="handDistribution">切换自提</view>
                    </view>
                    <view v-if="item.productDistributionType == 2">
                        <view
                            :class="item.storeId && item.distributionType == 2 ? 'storebtns' : 'storebtn'"
                            :data-index="index"
                            :data-id="item.productId"
                            :data-item="item"
                            @tap="handDistribution"
                        >
                            {{ item.storeId && item.distributionType == 2 ? '已选' : '选门店' }}
                        </view>
                    </view>
                    <!-- <view wx:if="{{item.productDistributionType == 1}}">
        <view class="storebtn" data-id="{{item.productId}}" data-item="{{item}}" wx:if="{{item.distributionType == 1 || item.productDistributionType == 3}}" bindtap="handDistribution" data-type="2">快递</view>
       </view> -->
                </view>

                <view class="storealign" v-if="item.productDistributionType == 3">亲~可选择上门自提，下单后可出示核销码到门店提取</view>

                <view class="storealign" v-if="item.productDistributionType == 2">亲，此商品仅能上门自提，下单后可出示核销码到门店提货</view>
            </view>
        </view>
        <view class="pages">
            <view class="margin-top-sm remarks bg-white">
                <image src="/static/images/remarks.png" class="remarksimg margin-left-sm"></image>
                <view class="text-darkGray text-df">订单备注：</view>
                <input
                    style="flex: 1; text-align: right"
                    class="margin-right-sm text-sm text-darkGrey"
                    @input="getremark"
                    :value="remark"
                    maxlength="100"
                    placeholder="最多只能输入一百个字"
                />
            </view>
        </view>
        <view class="pages">
            <view class="numbox margin-top-sm bg-white">
                <view>
                    <view class="numboxlist">
                        <view class="numboxlistleft">
                            <image src="/static/images/jine.png" class="numboximg margin-right-xs"></image>
                            <view class="text-df text-darkGray">商品金额:</view>
                        </view>
                        <view class="text-df text-darkGrey">¥{{ goodsInfo.productAmount }}</view>
                    </view>
                </view>
                <view>
                    <view class="numboxlist" v-if="listStatus">
                        <view class="numboxlistleft">
                            <image src="/static/images/yunfei2.png" class="numboximg margin-right-xs"></image>
                            <view class="text-df text-darkGray">运费:</view>
                        </view>
                        <view class="text-df text-darkGrey">¥{{ goodsInfo.freightAomunt }}</view>
                    </view>
                </view>
                <!-- <view catchtap="selectCoupon">
        <view class="numboxlist">
          <view class="numboxlistleft">
            <image src="{{shopimgUrl + 'payclock.png'}}" class="numboximg margin-right-xs"></image>
            <view class="text-df text-darkGray">优惠券:</view>
          </view>
          <view class="text-df text-darkGrey">{{cardinfo?('-¥'+cardinfo.deduction):'无'}}</view>
        </view>
      </view> -->
                <view class="numboxlist numsbottom">
                    <view class="text-df text-black text-bold">应付金额:</view>
                    <view style="color: #ff1b0b" class="text-price">
                        {{ filter.getPriceFormat(goodsInfo.totalAmount - (cardinfo.deduction ? cardinfo.deduction : 0)) }}
                    </view>
                </view>
            </view>
        </view>
        <view class="subbtn" @tap="handlepay">提交订单</view>

        <van-overlay :show="showMarker" @click="onMarkerHide" :z-index="9999">
            <view class="oreder-wrapper">
                <view class="oreder-wrapperbox" @tap.stop.prevent="shop">
                    <image class="isMarkerbg" :src="mallimgUrl + 'ismarkerbg.png'"></image>
                    <view class="markertext1">温馨提示</view>
                    <image class="isMarkerbtn" @tap.stop.prevent="makerpay" :src="mallimgUrl + 'ismarkerbtn.png'"></image>
                    <view class="markertext2">
                        创客大礼包属于创客用户的多重超值福利，用户下单并支付成功后，订单不支持取消、换货、退款；如订单有质量问题请联系意约客服处理，谢谢！
                    </view>
                    <view class="marker-icon" @tap.stop.prevent="onMarkerHide">
                        <van-icon name="close" size="60rpx" color="white" />
                    </view>
                </view>
            </view>
        </van-overlay>
    </view>
</template>
<script module="filter" lang="wxs" src="../../utils/filter.wxs"></script>
<script>
// pages/shopingmall/order.js
const _request = require('../../utils/request.js');

const app = getApp();
export default {
    data() {
        return {
            mallimgUrl: app.globalData.mallimgUrl,
            shopimgUrl: app.globalData.shopimgUrl,
            ids: '',

            //订单id
            defaultAddress: {
                name: '',
                phone: '',
                province: '',
                city: '',
                region: '',
                detailAddress: ''
            },

            //选中地址
            remark: '',

            //备注
            goodsInfo: {
                freightAomunt: 0,

                mallSkuStockDto: {
                    pic: '',
                    productName: '',
                    quantity: '',
                    priceMaker: '',
                    price: ''
                },

                mallProductDto: {
                    distributionType: 0
                },

                mallCartItemDtos: [],
                productAmount: '',
                totalAmount: 0
            },

            //订单详情
            total: 0,

            //总商品数
            // cardinfo: '', //选中的券信息
            productType: '',

            // 1-普通商品 2-创客卡礼包商品 3-意豆加现金商品4-纯意豆商品 5-盲盒商品
            showMarker: false,

            // 展示弹窗
            pageNo: 0,

            //页数
            skuStockId: '',

            //商品id
            quantity: '',

            //购买数量
            tap: '',

            //区分立即购买和结算
            spType: '',

            // 立即购买规格
            distributionType: '',

            //自提类型
            goodsType: '',

            //商品类型
            productCategoryId: '',

            productSkuCode: '',
            id: '',
            productDistributionType: '',
            stroelist: {},

            //门店信息
            carlist: {},

            //选中商品返回的列表给修改购物车接口
            distribution: '',

            specification: '',

            //商品规格
            checkMaker: false,

            //是否是创客用户
            listStatus: false,

            //运费设置
            feight: {
                remark: ''
            },

            currentsharer: '',
            addressList: '',
            storeid: '',
            undefined: '',
            storename: '',
            mobile: '',
            path: '',

            cardinfo: {
                deduction: false
            }
        };
    },
    onLoad: function (options) {
        console.log(options, 'options');
        this.setData({
            ids: options.ids,
            currentsharer: options.sharer && options.sharer != 'undefined' ? options.sharer : '',
            productType: options.productType,
            skuStockId: options.skuStockId,
            quantity: options.quantity,
            tap: options.tap,
            distributionType: options.distributionType,
            goodsType: options.goodsType,
            productCategoryId: options.productCategoryId,
            productSkuCode: options.productSkuCode,
            id: options.productId,
            productDistributionType: options.productDistributionType,
            specification: options.specification
        });
    },
    onShow: function () {
        this.setData({
            checkMaker: uni.getStorageSync('maker')?.ismaker || false
        });
        this.query(); //获取地址
    },
    methods: {
        //运费设置
        feightFun() {
            _request
                .get(
                    '/mall-feight-template/getDetail',
                    {
                        addressId: this.defaultAddress.id || '',
                        type: this.productType
                    },
                    app.globalData.mallType
                )
                .then((res) => {
                    if (res.data.code === 200) {
                        this.setData({
                            feight: res.data.data
                        });
                    }
                });
        },

        updatecar() {
            if (!this.tap) {
                _request
                    .postObj(
                        '/mall-cart-item/update',
                        {
                            userId: uni.getStorageSync('userId'),
                            id: this.carlist.id,
                            goodsType: this.carlist.goodsType,
                            type: this.carlist.type,
                            storeId: this.storeid ? this.storeid : '',
                            quantity: this.carlist.quantity,
                            productSkuId: this.carlist.productSkuId,
                            productSkuCode: this.carlist.productSkuCode,
                            productId: this.carlist.productId,
                            productCategoryId: this.carlist.productCategoryId,
                            price: this.carlist.price,
                            distributionType: this.distribution == 1 ? 1 : 2,
                            isPurchase: 0,
                            deleteStatus: 0
                        },
                        app.globalData.mallType
                    )
                    .then((res) => {
                        if (res.data.code === 200) {
                            uni.showToast({
                                title: res.data.message,
                                icon: 'none'
                            });
                            this.loaddata();
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                icon: 'none'
                            });
                        }
                    });
            }
        },

        //获取订单详情
        loaddata() {
            //购物车下单，运费接口type为空
            this.setData({
                productType: ''
            });
            let dataJson = {
                addressId: this.defaultAddress.id || '',
                ids: this.ids
            };

            _request.get('/mall-cart-item/getConfirmCartItem', dataJson, app.globalData.mallType).then((res) => {
                if (res.data.code === 200) {
                    let goodsInfo = res.data.data;
                    var _num = 0;
                    goodsInfo.mallCartItemDtos.forEach((e) => {
                        _num = e.quantity + _num;
                        e.spObj = JSON.parse(e.specification);
                        let list = [];
                        e.spObj.forEach((item) => {
                            list.push(item.key + ':' + item.value);
                        });
                        e.spType = list.join(',');
                    }); // 判断选择自提不显示运费和收获地址

                    const listStatus = goodsInfo.mallCartItemDtos.map((e) => {
                        if (e.productDistributionType == 2 || e.distributionType == 2) {
                            return false;
                        } else {
                            return true;
                        }
                    });
                    console.log(listStatus);
                    let Status = false;

                    if (listStatus.includes(true)) {
                        Status = true;
                    } else {
                        Status = false;
                    }

                    console.log(Status);
                    this.setData({
                        total: _num,
                        goodsInfo: goodsInfo,
                        listStatus: Status
                    });
                } else {
                    uni.showToast({
                        title: res.data.message,
                        icon: 'none'
                    });
                }
            });
        },

        // 获取地址
        query() {
            _request
                .get(
                    '/mall-address/list',
                    {
                        // userId: wx.getStorageSync('userId'),
                        offset: this.pageNo
                    },
                    app.globalData.mallType
                )
                .then((res) => {
                    if (res.data.code === 200) {
                        let list = res.data.data || [];
                        var address = uni.getStorageSync('_shopmalladdress');

                        if (address) {
                            address = JSON.parse(address);
                            this.setData({
                                defaultAddress: address
                            });
                        } else {
                            let defaultAddress = list.filter((e) => e.status == 1);
                            console.log(defaultAddress, 'defaultAddress');

                            if (defaultAddress && defaultAddress.length) {
                                this.setData({
                                    addressList: defaultAddress[0],
                                    defaultAddress: defaultAddress[0]
                                }); // wx.setStorageSync('_shopmalladdress', JSON.stringify(defaultAddress[0]))
                            }
                        } // if (this.data.defaultAddress && this.data.defaultAddress.id) {
                        //判断是立即购买跳转还是购物车结算

                        if (this.tap) {
                            this.buy();
                        } else {
                            this.loaddata(); //获取订单详情
                        }

                        if (this.storeid) {
                            // 判断是否选择门店了
                            if (uni.getStorageSync('select_storeid')) {
                                this.updatecar(); //修改购物率
                            }
                        }

                        this.feightFun(); //运费设置
                    } else {
                        uni.showModal({
                            title: '您还未填写地址',
                            content: '请先填写收货地址',

                            success(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '/shopingmall/addressmanager/addressmanager?selected=1'
                                    });
                                } else if (res.cancel) {
                                }
                            }
                        });
                    }
                });
        },

        // 立即购买
        buy() {
            let dataJson = {
                addressId: this.storeid ? '' : this.defaultAddress.id || '',
                skuStockId: this.skuStockId,
                quantity: this.quantity,
                specification: this.specification
            };

            _request.get('/mall-cart-item/getBuyNow', dataJson, app.globalData.mallType).then((res) => {
                if (res.data.code === 200) {
                    let goodsInfo = res.data.data;
                    let spObj = JSON.parse(goodsInfo.mallSkuStockDto.specification);
                    let list = [];
                    spObj.forEach((item) => {
                        list.push(item.key + ':' + item.value);
                    });
                    let spType = list.join(',');
                    var listStatus;

                    if (goodsInfo.mallProductDto.distributionType == 2 || this.storeid) {
                        listStatus = false;
                    } else {
                        listStatus = true;
                    }

                    this.setData({
                        goodsInfo: goodsInfo,
                        spType: spType,
                        total: this.quantity,
                        listStatus: listStatus
                    });
                } else {
                    uni.showToast({
                        title: res.data.message,
                        icon: 'none'
                    });
                }
            });
        },

        //跳转自提门店
        handDistribution(e) {
            console.log(this.tap, e.currentTarget.dataset);

            if (this.tap) {
                if (!this.storeid) {
                    uni.navigateTo({
                        url: '/shopingmall/stroemsg/stroemsg?productId=' + this.id
                    });
                } else {
                    this.setData({
                        storeid: '',
                        distributionType: this.goodsInfo.mallProductDto.distributionType,
                        listStatus: this.goodsInfo.mallProductDto.distributionType != 2
                    });
                    this.buy();
                    this.feightFun();
                }
            } else if (e.currentTarget.dataset.type == 2) {
                //判断是快递然后修改购物车
                this.setData({
                    carlist: e.currentTarget.dataset.item,
                    distribution: 1
                });
                this.updatecar();
            } else {
                if (e.currentTarget.dataset.id) {
                    uni.navigateTo({
                        url: '/shopingmall/stroemsg/stroemsg?productId=' + e.currentTarget.dataset.id + '&index=' + e.currentTarget.dataset.index
                    });
                }

                this.setData({
                    carlist: e.currentTarget.dataset.item,
                    distribution: 2
                });
            }
        },

        //切换
        handDistributions(e) {
            if (this.tap) {
                uni.navigateTo({
                    url: '/shopingmall/stroemsg/stroemsg?productId=' + this.id
                });
            } else {
                uni.navigateTo({
                    url: '/shopingmall/stroemsg/stroemsg?productId=' + e.currentTarget.dataset.id + '&index=' + e.currentTarget.dataset.index
                });
                this.setData({
                    carlist: e.currentTarget.dataset.item
                });
            }
        },

        // 跳转地址列表
        gotoSelectAddress() {
            uni.navigateTo({
                url: '/shopingmall/addressmanager/addressmanager?selected=1'
            });
        },

        // 跳转优惠券
        selectCoupon() {
            uni.navigateTo({
                url: '/shopingmall/couponindex/couponindex?cardinfo=' + JSON.stringify(this.cardinfo)
            });
        },

        // 关闭弹窗
        onMarkerHide() {
            this.setData({
                showMarker: false
            });
        },

        // 创客大礼包
        makerpay() {
            if (!this.defaultAddress.id) {
                uni.showToast({
                    title: '请先选择地址',
                    icon: 'none'
                });
                return;
            } else {
                _request
                    .postObj(
                        '/mall-order/submitOrder',
                        {
                            // userId: wx.getStorageSync('userId'),
                            sharer: this.currentsharer,
                            addressId: this.defaultAddress.id,
                            note: this.remark,
                            buyNow: true,
                            //是否立即购买 是 true 否(购物车) false
                            mallCartItemReqs: [
                                {
                                    deleteStatus: 0,
                                    distributionType: this.storeid ? 2 : 1,
                                    goodsType: this.goodsType,
                                    isPurchase: 1,
                                    price: this.goodsInfo.mallSkuStockDto.price,
                                    productId: this.id,
                                    type: 1,
                                    quantity: this.quantity,
                                    memberId: 1,
                                    //会员id 后端说写死不知道哪来的
                                    productSkuCode: this.productSkuCode,
                                    productSkuId: this.skuStockId,
                                    productCategoryId: this.productCategoryId,
                                    userId: uni.getStorageSync('userId'),
                                    specification: this.specification,
                                    storeId: this.storeid ? this.storeid : ''
                                }
                            ]
                        },
                        app.globalData.mallType
                    )
                    .then((res) => {
                        if (res.data.code === 200) {
                            this.setData({
                                showMarker: false
                            });
                            uni.navigateTo({
                                url:
                                    '/shopingmall/payment/payment?orderSn=' +
                                    res.data.data.orderSn +
                                    '&realityPayPrice=' +
                                    res.data.data.realityPayPrice +
                                    '&createordertime=' +
                                    res.data.data.createOrderTime +
                                    '&isLarge=' +
                                    res.data.data.isLarge +
                                    '&type=' +
                                    res.data.data.type
                            });
                            uni.setStorageSync('_shopmalladdress', '');
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                icon: 'none'
                            });
                        }
                    });
            }
        },

        // 提交订单跳转
        handlepay() {
            if (this.total < 1) {
                uni.showToast({
                    title: '库存不足, 请重新添加商品!',
                    icon: 'none'
                });
                return;
            }

            if (this.tap) {
                if (this.distributionType == 2) {
                    if (!this.storeid) {
                        uni.showToast({
                            title: '请先选择自提门店',
                            icon: 'none'
                        });
                        return;
                    }
                } else {
                    if (!this.defaultAddress.id) {
                        uni.showToast({
                            title: '请先选择地址',
                            icon: 'none'
                        });
                        return;
                    }
                }
            }

            if (!this.defaultAddress.id && this.distributionType != 2) {
                uni.showToast({
                    title: '请先选择地址',
                    icon: 'none'
                });
                return;
            } else {
                if (this.productType == 2) {
                    this.setData({
                        showMarker: true
                    });
                } else {
                    //判断是立即购买还是购物车结算
                    if (this.tap) {
                        _request
                            .postObj(
                                '/mall-order/submitOrder',
                                {
                                    // userId: wx.getStorageSync('userId'),
                                    addressId: this.defaultAddress.id,
                                    note: this.remark,
                                    sharer: this.currentsharer,
                                    buyNow: true,
                                    //是否立即购买 是 true 否(购物车) false
                                    mallCartItemReqs: [
                                        {
                                            deleteStatus: 0,
                                            distributionType: this.storeid ? 2 : 1,
                                            goodsType: this.goodsType,
                                            isPurchase: 1,
                                            price: this.goodsInfo.mallSkuStockDto.price,
                                            productId: this.id,
                                            type: 1,
                                            quantity: this.quantity,
                                            memberId: 1,
                                            //会员id 后端说写死不知道哪来的
                                            productSkuCode: this.productSkuCode,
                                            productSkuId: this.skuStockId,
                                            productCategoryId: this.productCategoryId,
                                            userId: uni.getStorageSync('userId'),
                                            specification: this.specification,
                                            storeId: this.storeid ? this.storeid : ''
                                        }
                                    ]
                                },
                                app.globalData.mallType
                            )
                            .then((res) => {
                                if (res.data.code === 200) {
                                    uni.navigateTo({
                                        url:
                                            '/shopingmall/payment/payment?orderSn=' +
                                            res.data.data.orderSn +
                                            '&realityPayPrice=' +
                                            res.data.data.realityPayPrice +
                                            '&createordertime=' +
                                            res.data.data.createOrderTime +
                                            '&isLarge=' +
                                            res.data.data.isLarge +
                                            '&type=' +
                                            res.data.data.type
                                    });
                                    uni.setStorageSync('_shopmalladdress', '');
                                } else {
                                    uni.showToast({
                                        title: res.data.message,
                                        icon: 'none'
                                    });
                                }
                            });
                    } else {
                        let list = this.goodsInfo.mallCartItemDtos; //遍历数据是否存在未选地址情况

                        const listStatus = list.map((item) => {
                            if (item.productDistributionType == 2 && !item.storeId) {
                                return false;
                            }

                            return true;
                        });
                        console.log(listStatus);

                        if (listStatus.includes(false)) {
                            uni.showToast({
                                title: '请先选择自提门店',
                                icon: 'none'
                            });
                            return;
                        }

                        _request
                            .postObj(
                                '/mall-order/submitOrder',
                                {
                                    // userId: wx.getStorageSync('userId'),
                                    sharer: this.currentsharer,
                                    addressId: this.defaultAddress.id,
                                    note: this.remark,
                                    buyNow: true,
                                    //是否立即购买 是 true 否(购物车) false
                                    mallCartItemReqs: this.goodsInfo.mallCartItemDtos
                                },
                                app.globalData.mallType
                            )
                            .then((res) => {
                                if (res.data.code === 200) {
                                    uni.navigateTo({
                                        url:
                                            '/shopingmall/payment/payment?orderSn=' +
                                            res.data.data.orderSn +
                                            '&realityPayPrice=' +
                                            res.data.data.realityPayPrice +
                                            '&createordertime=' +
                                            res.data.data.createOrderTime +
                                            '&isLarge=' +
                                            res.data.data.isLarge +
                                            '&type=' +
                                            res.data.data.type
                                    });
                                    uni.setStorageSync('_shopmalladdress', '');
                                } else {
                                    uni.showToast({
                                        title: res.data.message,
                                        icon: 'none'
                                    });
                                }
                            });
                    }
                }
            }
        },

        // 备注
        getremark(e) {
            this.setData({
                remark: e.detail.value
            });
        },

        shop() {
            console.log('占位：函数 shop 未声明');
        }
    }
};
</script>
<style>
page {
    background: #fbfbfb;
}

.pages {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    background-color: #fbfbfb;
}

.topbox {
    width: 710rpx;
    min-height: 180rpx;
    background: #fff;
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 2rpx 2rpx 8rpx 0rpx rgba(236, 236, 236, 0.4);
    border-radius: 12rpx;
}

.topboxaddicon {
    width: 80rpx;
    height: 80rpx;
    margin-left: 20rpx;
}

.toptext {
    display: flex;
    align-items: center;
}

.toprighticon {
    width: 32rpx;
    height: 32rpx;
}

.shoptexts {
    width: 710rpx;
    /* height: 240rpx; */
    background: #fff;
    margin-top: 20rpx;
    box-shadow: 2rpx 2rpx 8rpx 0rpx rgba(236, 236, 236, 0.4);
    border-radius: 12rpx;
}

.shoptext {
    align-items: center;
    display: flex;
}

.shoptext2 {
    width: 710rpx;
    background: #fff;
    margin-top: 20rpx;
    box-shadow: 2rpx 2rpx 8rpx 0rpx rgba(236, 236, 236, 0.4);
    border-radius: 12rpx;
    align-items: center;
    display: flex;
    flex-direction: column;
}

.stroes {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap-reverse;
}

.shopimg {
    width: 160rpx;
    height: 180rpx;
    margin: 0 30rpx;
}

.storetext {
    margin-top: 20rpx;
    margin-bottom: 10rpx;
    display: flex;
    justify-content: space-between;
    font-size: 28rpx;
    color: #666666;
}

.storeimg {
    width: 60rpx;
    height: 60rpx;
    margin: 0 30rpx;
}

.storebtn {
    min-width: 120rpx;
    max-width: 260rpx;
    padding: 0 10px;
    height: 56rpx;
    background: #ff8722;
    color: #ffffff;
    font-size: 28rpx;
    line-height: 54rpx;
    text-align: center;
    border-radius: 44rpx;
    margin-right: 20rpx;
    float: right;
    margin-bottom: 20rpx;
}

.storebtns {
    min-width: 120rpx;
    max-width: 260rpx;
    padding: 0 10px;
    height: 56rpx;
    background: #999999;
    color: #e7e7e7;
    font-size: 28rpx;
    line-height: 54rpx;
    text-align: center;
    border-radius: 44rpx;
    margin-right: 20rpx;
    float: right;
    margin-bottom: 20rpx;
}

.storealign {
    width: 710rpx;
    height: 38rpx;
    font-size: 24rpx;
    text-align: center;
    color: #ff8722;
    /* margin-bottom: 20rpx; */
    background: rgb(254, 245, 230);
    padding: 8rpx 0;
    border-radius: 0 0 8rpx 8rpx;
}

.remarks {
    width: 710rpx;
    height: 100rpx;
    box-shadow: 2rpx 2rpx 8rpx 0rpx rgba(236, 236, 236, 0.4);
    border-radius: 12rpx;
    align-items: center;
    display: flex;
}

.remarksimg {
    width: 32rpx;
    height: 32rpx;
    margin-right: 6rpx;
}

.numbox {
    width: 710rpx;
    /* height: 320rpx; */
    box-shadow: 2rpx 2rpx 8rpx 0rpx rgba(236, 236, 236, 0.4);
    border-radius: 12rpx;
    display: flex;
    flex-flow: column;
}

.numboximg {
    width: 32rpx;
    height: 32rpx;
}

.numboxlist {
    width: 670rpx;
    margin: 16rpx auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.numboxlistleft {
    display: flex;
    align-items: center;
}

.numsbottom {
    border-top: 1rpx solid #cacaca;
    padding: 20rpx 0;
    margin: 20rpx auto;
}

.subbtn {
    width: 670rpx;
    height: 88rpx;
    background: #ff8722;
    border-radius: 44rpx;
    margin: 100rpx auto;
    text-align: center;
    line-height: 88rpx;
    color: #fff;
    font-size: 32rpx;
}

/* 弹窗 */
.oreder-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    position: relative;
}

.oreder-wrapperbox {
    width: 550rpx;
    position: absolute;
    top: 170rpx;
    height: 750rpx;
    display: flex;
    justify-content: center;
}

.isMarkerbg {
    width: 550rpx;
    height: 750rpx;
    position: absolute;
}

.isMarkerbtn {
    width: 428rpx;
    height: 98rpx;
    position: absolute;
    z-index: 11;
    bottom: 50rpx;
}

.markertext1 {
    width: 160rpx;
    height: 36rpx;
    font-size: 36rpx;
    font-family: SourceHanSansSC-Medium, SourceHanSansSC;
    font-weight: 500;
    color: #ff6500;
    line-height: 54rpx;
    letter-spacing: 2px;
    position: absolute;
    z-index: 11;
    top: 276rpx;
}

.markertext2 {
    width: 436rpx;
    height: 208rpx;
    font-size: 28rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #b77b20;
    line-height: 40rpx;
    position: absolute;
    z-index: 11;
    bottom: 198rpx;
}

.marker-icon {
    position: absolute;
    bottom: -160rpx;
}

/* 
.service {
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
  box-shadow: 1px 1px 4px 0px rgba(236, 236, 236, 0.4);
  display: flex;
  justify-content: space-between;
}

.orderdetail-card{
  width: 96%;
  border-radius: 5px;
  padding: 20rpx;
  box-sizing: border-box;
  margin: 2% auto;
}
.orderdetail-shopname-wrap{
  display: flex;
  flex-direction: row;
  background: #FFFFFF;
  box-shadow: 1px 1px 4px 0px rgba(236, 236, 236, 0.4);
}
.user-apoint {
  margin-top: 10rpx;
  font-size: 33rpx;
}
.orderdetail-shopname-wrap{
  display: flex;
  flex-direction: row;
}
.order-detail-flex9{
  flex: 9;
}
.order-detail-flex14{
  flex: 14;
  margin-left: 20rpx;
}
.order-detail-text-align-right{
  text-align: right;
  color: #999999;
  font-size: 30rpx;
}
.shopicon {
  width: 40rpx;
  height: 40rpx;
  position: relative;
  top: 8rpx;
}
.order-detail-text-align-right{
  text-align: right;
  color: #999999;
  font-size: 30rpx;
}
.order-goods-image{
  width: 150rpx;
  height: 150rpx;
  border-radius: 5rpx;
  display: block;
}
.order-goods-desc{
  height: 150rpx;
}
.order-goods-num-text{
  font-size: 25rpx;
  color: #999999;
  margin: 10rpx 0;
}
.order-goods-price-text{
  font-size: 35rpx;
  color: #FF1717;
}
.order-goods-name-text{
  font-size: 35rpx;
  color: #333333;
}
.order-goods-detail-wrap{
  height: 220rpx;
}
.order-client-location-image{
  width: 80rpx;
  height: 80rpx;
}
.order-detail-flex4{
  position: relative;
  top: 20rpx;
}

.order-client-select-image{
  width: 30rpx;
  height: 30rpx;
}
.order-detail-flex2{
  position: relative;
  top: 30rpx;
}
.order-client-name-text{
  font-weight: 700;
  color: #333333;
  font-size: 40rpx;
}
.order-client-mobile-text{
  color: #333333;
  font-size: 35rpx;
  margin-left: 10rpx;
}
.order-client-addr-text{
  color: #666666;
  font-size: 35rpx;
}
.order-must-pay-text{
  font-size: 45rpx;
  font-weight: 700;
}
.order-must-pay-money{
  font-size: 40rpx;
  color: #FF1B0B;
}

.payment-comfirm-btn{
  font-size: 50rpx;
  padding: 10rpx;
  width: 80%;
  color: #ffffff;
  background-color: #FF8722;
  margin: 0 auto;
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  border-radius: 80rpx;
  margin-bottom: 30rpx;
} */
</style>
